package com.aidex.biz.service.impl;

import java.util.List;

import com.aidex.biz.domain.LinshiManage;
import com.aidex.common.annotation.DataScope;
import com.aidex.common.utils.SecurityUtils;
import com.aidex.common.utils.uuid.UUID;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.domain.entity.SysUser;
import com.aidex.common.core.domain.entity.SysDept;
import com.aidex.common.core.service.BaseServiceImpl;
import com.aidex.framework.cache.DeptUtils;
import com.aidex.framework.cache.UserUtils;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.aidex.biz.mapper.LinshiDeptManageMapper;
import com.aidex.biz.domain.LinshiDeptManage;
import com.aidex.biz.service.LinshiDeptManageService;
import org.springframework.transaction.annotation.Transactional;
import com.aidex.common.utils.NumberUtils;

/**
 * 部门临时督办Service业务层处理
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-02-20
 */
@Service
@Transactional(readOnly = true)
public class LinshiDeptManageServiceImpl extends BaseServiceImpl<LinshiDeptManageMapper, LinshiDeptManage> implements LinshiDeptManageService
{
    private static final Logger log = LoggerFactory.getLogger(LinshiDeptManageServiceImpl.class);

    /**
     * 获取单条数据
     * @param linshiDeptManage 部门临时督办
     * @return 部门临时督办
     */
    @Override
    public LinshiDeptManage get(LinshiDeptManage linshiDeptManage)
    {
        LinshiDeptManage dto = super.get(linshiDeptManage);
        return dto;
    }

    /**
     * 获取单条数据
     * @param id 部门临时督办id
     * @return 部门临时督办
     */
    @Override
    public LinshiDeptManage get(String id)
    {
        LinshiDeptManage dto = super.get(id);
        dto.setUserId(SecurityUtils.getUserId());
        dto.setUserName(SecurityUtils.getLoginUser().getUser().getName());
        return dto;
    }


    /**
     * 查询部门临时督办列表
     * @param linshiDeptManage 部门临时督办
     * @return 部门临时督办
     */
    @Override
    @DataScope(userAlias = "a",deptAlias = "a")
    public List<LinshiDeptManage> findList(LinshiDeptManage linshiDeptManage)
    {
        return super.findList(linshiDeptManage);
    }

    /**
     * 分页查询部门临时督办列表
     * @param linshiDeptManage 部门临时督办
     * @return 部门临时督办
     */
    @Override
    @DataScope(userAlias = "a",deptAlias = "a")
    public PageInfo<LinshiDeptManage> findPage(LinshiDeptManage linshiDeptManage)
    {
        return super.findPage(linshiDeptManage);
    }

    /**
     * 保存部门临时督办
     * @param linshiDeptManage
     * @return 结果
     */
    @Override
    public boolean save(LinshiDeptManage linshiDeptManage)
    {
        return super.save(linshiDeptManage);
    }


    /**
     * 删除部门临时督办信息
     * @param linshiDeptManage
     * @return 结果
     */
    @Override
    public boolean remove(LinshiDeptManage linshiDeptManage)
    {
        return super.remove(linshiDeptManage);
    }

    /**
     * 批量删除部门临时督办
     * @param ids 需要删除的部门临时督办ID
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int deleteLinshiDeptManageByIds(String[] ids)
    {
        return mapper.deleteLinshiDeptManageByIds(ids);
    }

    /**
     * 获取最大编号
     * @param linshiDeptManage 部门临时督办
     * @return 结果
     */
    @Override
    public int findMaxSort(LinshiDeptManage linshiDeptManage)
    {
        return NumberUtils.nextOrder(mapper.findMaxSort(linshiDeptManage));
    }

    @Override
    @Transactional(readOnly = false)
    public int batchInsert(LinshiManage linshiManage) {
        try {
            if(linshiManage.getArrayDeptIds()!=null&&linshiManage.getArrayDeptIds().size()>0){
                for (int i=0;i<linshiManage.getArrayDeptIds().size();i++) {
                    LinshiDeptManage linshiDeptManage = new LinshiDeptManage();
                    linshiDeptManage.setLinshiManageId(linshiManage.getId());
                    linshiDeptManage.setDeptId(linshiManage.getArrayDeptIds().get(i));
                    linshiDeptManage.setDeptName(linshiManage.getArrayDeptNames().get(i));
                    linshiDeptManage.setStatus(LinshiDeptManage.STATUS_DISABLE);
                    this.save(linshiDeptManage);
                }
            }
            return 1;
        }catch (Exception e){
            return 0;
        }
    }
}
